package com.example.controller;

import com.example.pojo.ItemCat;
import com.example.pojo.ResultBean;
import com.example.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Locale;

@RequestMapping("/category")
@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("queryByParentId/{parentId}")
    public ResultBean queryByParentId(@PathVariable("parentId") Long parentId){
        System.out.println("查询父级id为" + parentId);
        List<ItemCat> itemCats = categoryService.queryByParentId(parentId);
        return ResultBean.success(itemCats);
    }

    @GetMapping("queryAll")
    public ResultBean queryAll(){
        List<ItemCat> itemCats = categoryService.queryAll();
        return ResultBean.success(itemCats);
    }

    @GetMapping("queryParentsById/{id}")
    public ResultBean queryParentById(@PathVariable("id") Long id){
        List<Long> parents = categoryService.queryParentById(id);
        return ResultBean.success(parents);
    }
}
